@extends('app')
@include('UEditor::head')
@section('content')
<ul class="nav nav-tabs">
    <li><a href="/admin/teaches/index/course/index/{{$chapterid}}">列表</a></li>
     <li class="active"><a href="#">新增</a></li>
</ul>
<form id="newsForm">
        <div class="description2">
             <input type="hidden" name="chapterid" value="{{$chapterid}}">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章标题：</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" class="form-control" name="name" id="name" placeholder="标题" value="@if(!empty($result)){{$result->name}}@endif">
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
               <label class="col-xs-12 col-sm-3 col-md-2 control-label">简介：</label>
                <div class="col-sm-9 col-xs-12">
                    <script id="description" name="description"  style="width:100%;margin:0 auto;height:100px;" type="text/plain">
                    </script>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        <div class="tools">
            @if(!empty($office))
            <div class="form-group" id="office">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">教程地址：</label>
                <div class="col-sm-9 col-xs-12">
                    <input id="officeid" name="officeid" type="hidden" value="{{ $office->id }}">
                    {{ url($office->url) }}
                </div>
                <div class="clearfix"></div>
            </div>
            @if($office->pdf_url)
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">PDF地址：</label>
                <div class="col-sm-9 col-xs-12">
                    {{ url($office->pdf_url) }}
                </div>
                <div class="clearfix"></div>
            </div>
            @endif
            @if($office->swf_url)
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">SWF地址：</label>
                <div class="col-sm-9 col-xs-12">
                    {{ url($office->swf_url) }}
                </div>
                <div class="clearfix"></div>
            </div>
            @endif
            @else
            <div class="form-group" id="office">
                @if(!empty($office->url))
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">教程地址：</label>
                <div class="col-sm-9 col-xs-12">
                    <input id="officeid" name="officeid" type="hidden" value="{{ $office->id }}">
                    {{ url($office->url) }}
                </div>
                @endif
                <div class="clearfix"></div>
            </div>
            @endif
            <div class="form-group" id="officeupload">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">上传教程：</label>
                <div class="col-sm-9 col-xs-12">
                    <input id="uploadoffice" name="uploadoffice" type="file" multiple="true">
                    <div id="imgbox"></div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        
        <div class="content-layout end-layout">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">教程价格：</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="number" name="price" class="form-control" value="@if(!empty($result)){{$result->price?$result->price:0}}@else 0 @endif">
                    <div class="help-block" >为0则为免费课程。</div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">教程排序：</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="number" name="sort" class="form-control" value="@if(!empty($result)){{$result->sort?$result->sort:0}}@else 0 @endif">
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章权限：</label>
                <div class="col-sm-9 col-xs-12">
                    <label class="radio-inline">
                    	<input type="radio" name="need_login"  value="1"  @if(!empty($result) && $result->need_login == 1) checked @endif>&nbsp;&nbsp;需要用户登录
                	</label>
                    <label class="radio-inline">
                    	<input type="radio" name="need_login"  value="0" @if(empty($result) || $result->need_login == 0) checked @endif>&nbsp;&nbsp;不需要用户登录
        			</label>
                </div>
                <div class="clearfix"></div>
            </div>
            <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
            <input type="hidden" name="teachesType" value="2">
            <input type="hidden" name="contentid" value="@if(!empty($result)){{$result->id}}@endif">
            {!! csrf_field() !!}
            <div class="form-inline">
                <div class="form-group">
                  <button type="button" class="btn btn-info" id="publish_save" onclick="saveTeachesData('/admin/teaches/index/course','newsForm',2)">
                    <i class="icon-ok bigger-110"></i>
                    Submit
                  </button>
                </div>
                <div class="form-group col-xs-offset-1">
                  <button type="reset" class="btn">
                    <i class="icon-undo bigger-110"></i>
                    Reset
                  </button>
                </div>
            </div>
        </div>
</form>

<script type="text/javascript">
<!--

var ue1 = UE.getEditor('description');
ue1.ready(function() {
	ue1.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.    
	ue1.setContent('@if(!empty($result)){!! $result->description !!}@endif');
});

	$(function(){
		/***图片上传****/
    	$("#uploadoffice").uploadify({
    	    'formData'     : {
    	        'fileField':'upfile',
    	        '_token':'{{ csrf_token() }}',
    	        'app':'teaches_content'
    	    },
    	    "width"           : 120,
    	    "height"          : 30,
    	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
    	    "fileObjName"     : "upfile",
    	    "buttonText"      : "上传教程",
    	    "uploader"        : '/admin/upload/office',
    	    'removeTimeout'	  : 1,
    	    'fileTypeExts'	  : '*.doc; *.docx; *.ppt; *.pptx; *.xlsx; *.xls;',
    	    'onUploadSuccess':function(file, data, response){
    	    	var data = eval('(' + data + ')');
    	        if (data.status == 'success') {
    	            var html="<label class=\"col-xs-12 col-sm-3 col-md-2 control-label\">教程地址：</label>"+
    	            		"<div class=\"col-sm-9 col-xs-12\"><input id=\"officeid\" name=\"officeid\" type=\"hidden\" value='"+data.id+"' >"+data.url+"</div><div class=\"clearfix\"></div>";
    	            $('#office').html(html);
    	        }else{
    	            alert(data.msg);
    	            return false;
    	        }
    
    	    }
    
    	});
	});

//-->
</script>
@endsection
